package com.etc.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/img")
public class ImageServelt extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// img?id=123123.png
		String name = req.getParameter("id");
		String path = "d:/tmp1/";
		FileInputStream fis = new FileInputStream(new File(path, name));
		OutputStream os = resp.getOutputStream();
		
	    int len = 0;
        byte[] buffer = new byte[1024];
        while ((len = fis.read(buffer)) > 0) {
        	os.write(buffer, 0, len);
        }
		
        os.flush();
        os.close();
        fis.close();
		
	}

}
